package main

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

type request struct {
	ID     int64    `json:"id"`
	Params []string `json:"params"`
	Method string   `json:"method"`
}

type rsp struct {
	ID     int64  `json:"id"`
	Result string `json:"result"`
	Error  string `json:"error"`
}

func main() {
	requestData := request{
		ID:     0,
		Params: []string{"czc", "heaode"},
		Method: "HelloService.Hello",
	}

	data, err := json.Marshal(requestData)
	if err != nil {

		error.Error(err)
	}
	url := "http://localhost:1234/jsonrpc"
	req, err := http.NewRequest("POST", url, bytes.NewBuffer(data))
	if err != nil {
		error.Error(err)
	}
	req.Header.Set("Content-Type", "application/json")
	client := http.DefaultClient
	response, err := client.Do(req)
	if err != nil {
		error.Error(err)
	}

	fmt.Println(response)
	defer response.Body.Close()
	BodyData, err := io.ReadAll(response.Body)
	if err != nil {
		error.Error(err)
	}
	fmt.Println(string(BodyData))

	info := rsp{}
	json.Unmarshal(BodyData, &info)
	fmt.Println(info)
}
